/*
 * Copyright @ 苏州瑞云信息技术有限公司 All rights reserved.
 */
package cn.com.recloud.bbs.controller;


import cn.com.recloud.bbs.vo.MyFavoriteVO;
import cn.com.recloud.core.util.Result;
import cn.com.recloud.one.spring.exception.OneException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import cn.com.recloud.one.spring.controller.BaseController;

import cn.com.recloud.bbs.entity.bbs_my_favorite_log;
import cn.com.recloud.bbs.service.MyFavoriteLogService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author keblea xie
 * @date 2020-06-08
 */
@RestController
@RequestMapping("/api/bbs/myfavoritelog")
@Api(tags = "个人中心我的收藏相关接口")
public class MyFavoriteLogController extends BaseController<bbs_my_favorite_log,MyFavoriteLogService> {
    @Resource
    MyFavoriteLogService myFavoriteLogService;

    @PostMapping("saveorcancelfavorite")
    @ApiOperation("收藏/取消收藏")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bbsMyFavoriteLog", value = "收藏的对象")
    })
    public Result saveOrCancelFavorite(@RequestBody bbs_my_favorite_log bbsMyFavoriteLog){
        myFavoriteLogService.saveFavorite(bbsMyFavoriteLog);
        return Result.SUCCESS;
    }

    @GetMapping("myfavoritelist")
    @ApiOperation("查询我的收藏列表")
    public Result myFavoriteList(String name,String type,
                                 @RequestParam(required = false,defaultValue = "1") Integer pageIndex,
                                 @RequestParam(required = false,defaultValue = "15") Integer pageSize){
        if(StringUtils.isBlank(type)){
            throw new OneException("类型不能为空");
        }
        List<MyFavoriteVO> list = myFavoriteLogService.findMyFavoriteList(name,type,pageIndex,pageSize);
        return new Result(list);
    }
}

